package com.fhd.dao.Manager;

import com.fhd.dao.BaseDao;
import com.fhd.pojo.Client;
import com.fhd.pojo.Manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ManagerDaoImplement implements ManagerDao{

    // 通过账号得到管理端
    @Override
    public Manager getLoginManager(Connection conn, String userCode) {
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Manager manager = new Manager();

        try {
            if (conn != null) {
                // 编写sql语句,并把参数放进数组中
                String sql = "select * from manager where user_code = ?";
                Object[] parameters = {userCode};
                rs = BaseDao.executeQuery(conn, pstmt, rs, sql, parameters);

                if(rs.next()) {
                    manager.setId(rs.getInt("id"));
                    manager.setUserCode(rs.getString("user_code"));
                    manager.setUserPassword(rs.getString("user_password"));
                    manager.setUserName(rs.getString("user_name"));
                    manager.setRoleId(rs.getInt("role_id"));
                }
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            BaseDao.close(null,pstmt,rs);
        }
        return manager;
    }
}
